﻿@{
    ViewData["Title"] = "工作站修改";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>新增工作站</title>
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script>
</head>
<body>
    <form class="layui-form" action="" onsubmit="return false">
        <div class="layui-form-item">
            <label class="layui-form-label">工作站编码</label>
            <div class="layui-input-block" style="width:400px">
                <input type="text" name="workstationCode" id="workstationCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                <input type="checkbox" name="autoGenerate" lay-skin="switch" lay-text="自动生成" lay-filter="autoGenerate" style="display: inline-block; margin-left: 10px;">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工作站名称</label>
            <div class="layui-input-block">
                <input type="text" name="workstationName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工作站地点</label>
            <div class="layui-input-block">
                <input type="text" name="workstationAddress" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所在车间</label>
            <div class="layui-input-block">
                <select name="workshopId" id="workshopId" lay-verify="required">
                    <option value="0">请选择</option>
                    <option value="2">车间1</option>
                    <option value="3">车间2</option>
                    <option value="4">车间3</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所属工序</label>
            <div class="layui-input-block">
                <select name="processId" id="processId" lay-verify="required">
                    <option value="0">请选择</option>
                    <option value="1">制造发动机</option>
                    <option value="2">制造机翼</option>
                    <option value="3">制造机身</option>
                    <option value="4">制造电池</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="radio" name="enableFlag" id="是" value="是" title="是" checked>
                <input type="radio" name="enableFlag" id="否" value="否" title="否">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="remark"></textarea>
            </div>
        </div>
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
        
    </form>
    <script type="text/javascript">
        layui.use('form', function () {
            const form = layui.form;
            form.render();
            // 生成随机代码
            function generateRandomCode() {
                return Math.random().toString(36).substr(2, 10).toUpperCase();
            }
            // 自动生成客户编码
            form.on('switch(autoGenerate)', function (data) {
                if (data.elem.checked) {
                    $('#workstationCode').val(generateRandomCode());
                } else {
                    $('#workstationCode').val('');
                }
            });
        });
    </script>

    <script>
        layui.use('table', function () {
            var $ = layui.$;
            var layer = layui.layer;
            var util = layui.util;
            var form = layui.form;
            var layer = layui.layer;
            var util = layui.util;

            var table = layui.table;
            var form = layui.form;
            var laydate = layui.laydate;
            var laypage = layui.laypage;

            function getEdit() {
                $('#workstationCode').val(parent.workstationCode);
                $("[name='workstationName']").val(parent.workstationName);
                $("[name='workstationAddress']").val(parent.workstationAddress);
                $("[name='workstationName']").val(parent.workstationName);
                $("#workshopId").val(parent.workshopID);
                form.render("select")
                $("[name='processId']").val(parent.processId);
                form.render("select")
                if (parent.enableFlag == "是") {
                    $("#是").prop("checked", true);
                }
                else {
                    $("#否").prop("checked", true);
                }
                
                
                $("[name='remark']").val(parent.remark);
            }
            getEdit();
            // 事件
            //表单操作

            // 表单提交事件
            form.on('submit(demo1)', function (data, index) {
                    var field = data.field; // 获取表单字段值

                    console.log(field);
                var UpdateDto = {
                    Id: parent.id,
                    WorkstationCode: field.workstationCode,
                    WorkstationName: field.workstationName,
                    WorkstationAddress: field.workstationAddress,
                    WorkshopID: field.workshopId,
                    ProcessID: field.processId,
                    EnableFlag: field.enableFlag,
                    Remark: field.remark,
                    CreateBy: parent.createBy,
                    CreateTime: parent.createTime
                };
                    console.log(UpdateDto);

                    $.ajax({
                    url: '/Li/UpdateWorkStation',
                        type: 'Get',
                        data: UpdateDto,
                        dataType: "json",
                        success: function (res) {
                            if (res != null) {
                                alert("修改成功");
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index);//再执行关闭
                                //跳转
                                //window.location.href = "/Main/Student/"
                            }
                            else {
                                alert("修改失败");
                            }

                        }
                    });
                    return false; // 阻止默认 form 跳转
                });



        })

    </script>
</body>
</html>